/**
 * @Title: RoleController
 * @Package cn.com.yiqi.wsc.portal.controller.admin
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-胥钰淋
 * @date 2017/2/14 17:13
 * @version V1.0
 */
package cn.com.yiqi.wsc.portal.controller.admin;

import cn.com.yiqi.wsc.common.Result;
import cn.com.yiqi.wsc.common.ResultStatusEnum;
import cn.com.yiqi.wsc.dao.role.criteria.RoleCriteria;
import cn.com.yiqi.wsc.portal.controller.BaseController;
import cn.com.yiqi.wsc.service.role.RoleService;
import cn.com.yiqi.wsc.service.role.dataobject.RoleDO;
import cn.com.yiqi.wsc.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 会员系统组-胥钰淋
 * @ClassName: RoleController
 * @Description: TODO
 * @date 2017/2/14 17:13
 */
@Controller
@RequestMapping("/role")
public class RoleController extends BaseController {


    @Autowired
    private RoleService roleService;

    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public ModelAndView index() {
        ModelAndView mv = new ModelAndView("role/index");
        this.getUserData(mv);
        return mv;
    }


    /**
     * 查询列表
     *
     * @param criteria
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public Result pageList(@RequestBody RoleCriteria criteria) {
        Result result = new Result();

        result = roleService.pageList(criteria);

        return result;
    }

    /**
     * 修改
     *
     * @param roleDO
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public Result update(@RequestBody RoleDO roleDO) {
        Result result = new Result();

        if (roleDO.getId() == null) {
            result.setErrMsg("参数错误");
            result.setStatus(ResultStatusEnum.参数错误.getCode());
            return result;
        }

        roleDO.setUpdateUserId(userService.getCurrentUserId());


        result = roleService.update(roleDO);

        return result;
    }

    /**
     * 修改
     *
     * @param roleDO
     * @return
     */
    @RequestMapping("/detail")
    @ResponseBody
    public Result detail(@RequestBody RoleDO roleDO) {
        Result result = new Result();

        if (roleDO.getId() == null) {
            result.setErrMsg("参数错误");
            result.setStatus(ResultStatusEnum.参数错误.getCode());
            return result;
        }


        result = roleService.detail(roleDO);

        return result;
    }

    /**
     * 添加
     *
     * @param roleDO
     * @return
     */
    @RequestMapping("/insert")
    @ResponseBody
    public Result insert(@RequestBody RoleDO roleDO) {
        Result result = new Result();

        roleDO.setInsertUserId(userService.getCurrentUserId());
        result = roleService.insert(roleDO);

        return result;
    }


    /**
     * 删除
     *
     * @param roleDO
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Result delete(@RequestBody RoleDO roleDO) {
        Result result = new Result();

        if (roleDO.getId() == null) {
            result.setErrMsg("参数错误");
            result.setStatus(ResultStatusEnum.参数错误.getCode());
            return result;
        }
        result = roleService.delete(roleDO);
        return result;
    }


}
